package com.project.running.Service.Impl;

import com.project.running.Service.MemberInfoService;

import com.project.running.bean.Memberinfo;
import com.project.running.dao.MemberinfoMapper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/10/7-10-07-10:21
 * @Description：com.project.running.Service.Impl
 */

@Service
public class MemberInfoServiceImpl implements MemberInfoService {

    @Autowired
    MemberinfoMapper mapper;
    @Override
    public int getOnlineNum() {
//        SqlSession session = SqlSessionUtil.openSession();
//        MemberinfoMapper mapper = session.getMapper(MemberinfoMapper.class);

//        try{
//            return mapper.findOnlineNum();
//        }finally {
//            session.close();
//        }
        return mapper.findOnlineNum();
    }

    @Override
    public List<Memberinfo> getTenOfMember() {

//        SqlSession session = SqlSessionUtil.openSession();
//        MemberinfoMapper mapper = session.getMapper(MemberinfoMapper.class);

        List<Memberinfo> tenOfMemberInfo = mapper.getTenOfMemberInfo();
        while(tenOfMemberInfo.size()>10){
            tenOfMemberInfo.remove(10);
        }
        return tenOfMemberInfo;
    }
}
